<?php 
/* SVN FILE: $Id$ */
/* User Test cases generated on: 2010-02-13 15:11:24 : 1266066684*/
App::import('Model', 'User');

class UserTestCase extends CakeTestCase
{
    var $User = null;
/*    var $fixtures = array(
        'app.user',
    );*/
    
    function startTest()
    {
        $this->User = &ClassRegistry::init('User');
    }
    
    function testUserInstance()
    {
        $this->assertTrue(is_a($this->User, 'User'));
    }

    function testUserFind()
    {
        $this->User->recursive = -1;
        $results = $this->User->find('first');
        $this->assertTrue(! empty($results));

        $expected = array(
            'User'=>array(
                'id'=>1, 'username'=>'mohammadkotb', 'password'=>'407dd4e51607714283eba7e97182a815', 'first_name'=>'mohammad', 'middle_name'=>'ibrahim', 'last_name'=>'kotb', 'birthdate'=>'2010-02-16 10:33:00', 'user_type_id'=>1, 'email'=>'mohammad.i.kotb@gmail.com', 'profile_picture_url'=>'the url of the picture', 'academic_year'=>'2012', 'acm_member'=>1, 'custom_link_url'=>'', 'created'=>'2010-02-16 10:34:30', 'modified'=>'2010-02-16 10:34:30', 'phone_number' => NULL, 'user_manager' => 0
            )
        );
        $this->assertEqual($results, $expected);
    }

    function testValidateBirthDate()
    {
		$data = array();
		$data['birthdate'] = '1990-03-20';
		$this->assertTrue($this->User->validate_birth_date($data));
		$data['birthdate'] = '2009-03-20';
		$this->assertFalse($this->User->validate_birth_date($data));
    }

	function testCalcAcademic()
	{
		$this->assertEqual($this->User->calc_academic_year(2), '2011');
		$this->assertNotEqual($this->User->calc_academic_year(1), '2011');
	}
}


class UserWebTestCase extends CakeWebTestCase
{
	function testLoginGoodUsername()
	{
	  $this->addHeader("User-Agent: CakePHP/SimpleTest");
      $this->get('http://localhost/acm_site/users/login');
	  $this->assertText('Login');
      $this->setField('username', 'ahmed');
	  $this->setField('password', 'ahmed');
      $this->click('Login');
	  $this->assertText('Welcome');
      // $this->assertText(__('Users'));
   }

   function testLoginBadUsername()
   {
   	  $this->addHeader("User-Agent: CakePHP/SimpleTest");
      $this->get('http://localhost/acm_site/users/login');
      $this->setField('username', 'ahmed');
	  $this->setField('password', 'ahmedzzzz');
      $this->click('Login');
      $this->assertText(__('Sorry, the information '));
   }
/*
   function testWikipediaArticle()
   {
      $this->addHeader("User-Agent: CakePHP/SimpleTest");
      $this->get('http://en.wikipedia.org/wiki/Cakephp');
      $this->assertText('Unit testing');
   }
*/
	function testGoogle()
	{
      $this->addHeader("User-Agent: CakePHP/SimpleTest");
      $this->get('http://www.google.com');
      $this->assertText('Google');
	}
}
?>
